// pages/user/user.js
Page({
  data:{
    logincode:'',
    password:'',
     motto: 'Hello World',
    userInfo: {}
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
      wx.login({
        success: function(res){
            console.log(res)
                wx.request({
                  url:'http://lendgiant.cn/index/wxsmallLogin',                    data: {"jscode":res.code},      
                  header:  {'Content-Type': 'application/json'},                   success: function(res) {    
                    console.log(res.data.loginstatus);
                    console.log(res.data.msg)
                  }
                });   
          }
    })
var app = getApp()
var that=this;
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })

  },
   //事件处理函数
  bindViewTap: function() {
   wx.redirectTo({
        url: '/pages/caculate/caculate'
    })
  },

  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  reg:function(){
    //注册

  },
  forget:function(){
    //忘记密码
  },
    inputlogincode:function(e){
   this.setData({
      logincode:e.detail.value,
   });
  },
    inputpassword:function(e){
   this.setData({
      password:e.detail.value,
   });
  },
  login:function(){
    //登录
    var that=this;
    console.log("开始登录"+that.data.logincode.length+" "+that.data.password.length)
    if(that.data.logincode.length>0 && that.data.password.length>0){  
   wx.request({
      url:'https://lendgiant.cn/index/loginWXX',
      data: {
        'logincode':that.data.logincode,
        'password':that.data.password
      },
      header: {'Content-Type': 'application/json'},
      success: function(res) {
        if(res.data.result){
            wx.showToast({
              title: '登录成功',
              icon: 'success',
              duration: 10000
            });
          setTimeout(function(){
            wx.hideToast();
            wx.navigateTo({url:'/pages/discover/discover'});
          },2000);
      }

    }
    })
  }else{
         wx.showToast({
              title: '登录成功',
              icon: 'success',
              duration: 10000
            });
          setTimeout(function(){
            wx.hideToast();
            wx.navigateTo({url:'/pages/discover/discover'});
          },2000);
  }

  },
   onShareAppMessage: function () {
    return {
      title: '蓝晶领招聘小程序',
      desc: '蓝晶领招聘小程序',
      path: '/pages/discover/discover'
    }
  }

})